package com.yang.code_sample.performance_count.test;

import com.yang.code_sample.performance_count.controller.MetricsCollector;
import com.yang.code_sample.performance_count.entity.RequestInfo;
import com.yang.code_sample.performance_count.function.ConsoleReporter;
import com.yang.code_sample.performance_count.function.EmailReporter;
import com.yang.code_sample.performance_count.service.MetricsStorage;
import com.yang.code_sample.performance_count.service.impl.RedisMetricsStorage;

/**
 * @Description: 测试类
 * @Author: 杨 强
 * @CreateTime: 2022-10-13 17:55
 */

public class Demo {
    public static void main(String[] args) {
        // 控制台打印数据报表
        MetricsStorage storage = new RedisMetricsStorage();
        ConsoleReporter consoleReporter = new ConsoleReporter(storage);
        consoleReporter.startRepeatedReport(60, 60);

        // 邮件发送数据报表
        EmailReporter emailReporter = new EmailReporter(storage);
        emailReporter.addToAddress("wangzheng@xzg.com");
        emailReporter.startDailyReport();

        // 保存请求数据
        MetricsCollector collector = new MetricsCollector(storage);
        collector.recordRequest(new RequestInfo("register", 123, 10234));
        collector.recordRequest(new RequestInfo("register", 223, 11234));
        collector.recordRequest(new RequestInfo("register", 323, 12334));
        collector.recordRequest(new RequestInfo("login", 23, 12434));
        collector.recordRequest(new RequestInfo("login", 1223, 14234));

        try {
            Thread.sleep(100000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
